package com.gjy.reflect;

import java.lang.reflect.Method;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-12-15 17:03:49
 */
public class ListReflectTest {

    public static void main(String[] args) throws Exception {
        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(2);

        Class<? extends List> clazz = list.getClass();
        Method add = clazz.getDeclaredMethod("add", Object.class);
        add.invoke(list, LocalDate.now());

//        list.forEach(System.out::println);
//        System.out.println(list);

        Method get = clazz.getDeclaredMethod("get", int.class);
        Object invoke = get.invoke(list, 2);

        System.out.println("invoke = " + invoke);
        System.out.println("invoke = " + invoke.getClass());
    }
}
